library _;

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_app/Const/IFinal.dart';
import 'package:flutter_app/Model/Enums.dart';
import 'package:flutter_app/Model/UserModel.dart';
import 'package:flutter_app/Page/Main/Register/main.dart';
import 'package:flutter_app/Util/App/AppUtils.dart';
import 'package:flutter_app/View/MyViews.dart';
import 'package:flutter_yfree/YFree.dart';
import 'package:sharesdk_plugin/sharesdk_plugin.dart';

part 'controller.dart';

part 'view.dart';

class LoginPage extends YPage {
  LoginPage({String? loginname}) {
    textController_account_loginname.text = loginname ?? "";
  }

  Enum_LoginType loginType = Enum_LoginType.UnKnown;
  bool isSelectProtocol = false, isShowPassword = false;
  String? codeParams;
  var codeTimeLeft = 0;
  Timer? timer_code;

  final textController_account_loginname = TextEditingController(), textController_account_password = TextEditingController(), textController_account_code = TextEditingController(), focusNode_loginname = FocusNode(); //账号登录
  final textController_code_server_phone = TextEditingController(), textController_code_server_code = TextEditingController(); //验证码_Server
  final textController_code_sdk_phone = TextEditingController(), textController_code_sdk_code = TextEditingController(); //验证码_SDK

  @override
  void yOnCreate() {
    focusNode_loginname.addListener(() {
      if (!focusNode_loginname.hasFocus) controller_refreshCode();
    });
    controller_initLoginType();
  }

  @override
  void yOnDestory() {
    timer_code?.cancel();
    textController_account_loginname.dispose();
    textController_account_password.dispose();
    textController_code_server_phone.dispose();
    textController_code_server_code.dispose();
  }

  @override
  Widget yBuild(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        view_topBar(),
        Container(
          margin: EdgeInsets.fromLTRB(20, 40, 20, 0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text("亲，欢迎登录", style: TextStyle(fontSize: 30)),
              YSpacer(height: 10),
              !IFinal.Configs_Server.login.account ? YEmpty() : view_title(),
              YSpacer(height: 30),
              YAnimatedSwitcher(child: view_main()),
              YSpacer(height: 5),
              view_protocol(),
            ],
          ),
        ),
      ],
    );
  }
}
